<?php namespace App\Http\Controllers\user\collect;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Input;
use App\Models\Collecttion;

class IndexController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		return view('user.collect.index');
	}

	public function addCollect()
	{
		$type = (int)Input::get("type");
		$relate_id = (int)Input::get("relate_id");
		$uid = $this->getUid();
		if(!$uid){
			return 2;
		}
		$model = Collecttion::where("uid", $uid)->where("type", $type)->where("relate_id", $relate_id);
		if($model->count()){
			// 取消收藏
			$model->get()[0];
			if($model->delete()){
				return 0;
			}
		}else{
			// 添加收藏
			$model = new Collecttion;
			$model->uid = $uid;
			$model->type = $type;
			$model->relate_id = $relate_id;
			if($model->save()){
				return 1;
			}
		}
	}



	// 后台用户列表

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}
}
